Skip to content

GH-3902: Add Kotlin Coroutines Support #3905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 17, 2022

Conversation

artembilan
Copy link
Member

Fixes #3902

  • Add isAsync() propagation from the MessagingMethodInvokerHelper to the AbstractMessageProducingHandler to set into its async property. The logic is based on a CompletableFuture, Publisher or Kotlin suspend return types of the POJO method
  • Introduce IntegrationMessageHandlerMethodFactory and IntegrationInvocableHandlerMethod to extend the logic to newly introduced ContinuationHandlerMethodArgumentResolver and call for Kotlin suspend functions.
  • Remove MessageHandlerMethodFactoryCreatingFactoryBean since its logic now is covered with the IntegrationMessageHandlerMethodFactory
  • Kotlin suspend functions are essentially reactive, so use CoroutinesUtils.invokeSuspendingFunction() and existing logic in the AbstractMessageProducingHandler to deal with Publisher reply

@artembilan artembilan marked this pull request as ready for review October 4, 2022 21:29
@artembilan
Copy link
Member Author

This is one side of the medal.
It can be merged after review or @MessagingGateway part can be incorporated into this one.

@artembilan artembilan force-pushed the GH-3902 branch 2 times, most recently from 9eac6dc to 1e62d21 Compare October 6, 2022 20:33
@tomvandenberge
Copy link
Contributor

That was fast! This is great news.

As I'm not familiar with Spring Integration internals, it's not totally clear to me what your changes mean to me as an end user. Could you maybe provide some examples of how users can now leverage Kotlin suspending functions together with Spring Integration?

@artembilan
Copy link
Member Author

@garyrussell
Copy link
Contributor

Needs rebase (what's new).

artembilan and others added 7 commits October 17, 2022 16:55
Fixes spring-projects#3902

* Add `isAsync()` propagation from the `MessagingMethodInvokerHelper`
to the `AbstractMessageProducingHandler` to set into its `async` property.
The logic is based on a `CompletableFuture`, `Publisher` or Kotlin `suspend`
return types of the POJO method
* Introduce `IntegrationMessageHandlerMethodFactory` and `IntegrationInvocableHandlerMethod`
to extend the logic to newly introduced `ContinuationHandlerMethodArgumentResolver`
and call for Kotlin suspend functions.
* Remove `MessageHandlerMethodFactoryCreatingFactoryBean` since its logic now is covered with the
`IntegrationMessageHandlerMethodFactory`
* Kotlin suspend functions are essentially reactive, so use `CoroutinesUtils.invokeSuspendingFunction()`
and existing logic in the `AbstractMessageProducingHandler` to deal with `Publisher` reply

* Fix `GroovySplitterTests` for the current code base

* Add `kotlinx.coroutines.flow.Flow` support
The `Flow` is essentially a multi-value reactive `Publisher`,
so use `ReactiveAdapterRegistry` to convert any custom reactive streams result to `Flux` and `Mono`
which we already support as reply types

* Add docs for `Kotlin Coroutines`
Rearrange the doc a bit extracting Kotlin support to individual `kotlin-functions.adoc` file

* Fix missed link to `reactive-streams.adoc` from the `index-single.adoc`
* Fix unintended Javadocs formatting in the `AbstractMessageProducingHandler`

* Add suspend functions support for Messaging Gateway
* Add convenient `CoroutinesUtils` for Coroutines types and `Continuation` argument fulfilling via `Mono`
* Treat `suspend fun` in the `GatewayProxyFactoryBean` as a `Mono` return
* Convert `Mono` to the `Continuation` resuming in the end of gateway call

* Document `suspend fun` for `@MessagingGateway`
* Mention default sync behavior in the docs
Co-authored-by: Gary Russell <[email protected]>
@garyrussell garyrussell merged commit ff076b6 into spring-projects:main Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Kotlin Coroutines Support
3 participants